import { reqCateList, reqSwiperList, reqFloorList } from '@/api/index'
export default {
  namespaced: true,
  state: {
    cateList: [],
    swiperList: [],
    floorList: []
  },
  mutations: {
    // 定义mutation将数据存储起来
    addAateList(state, cateList) {
      state.cateList = cateList.slice(0, 15)
    },
    // 2.定义存储轮播图的数据的mutation
    addSwiperList(state, swiperList) {
      state.swiperList = swiperList
    },
    // 3.定义存储楼层数据的mutation
    addFloorList(state, floorList) {
      state.floorList = floorList
    }
  },
  actions: {
    // 因为请求数据是异步的所以要写在actions中
    // 1.定义获取三级菜单的action
    async getCateList(context) {
      const res = await reqCateList()
      // console.log(res)
      context.commit('addAateList', res.data)
    },

    // 2.定义获取轮播图数据的action
    async getSwiperList(context) {
      const res = await reqSwiperList()
      // console.log(res)
      context.commit('addSwiperList', res.data)
    },
    // 3.定义获取楼层数据的action
    async getFloorList(context) {
      const res = await reqFloorList()
      // console.log(res)
      context.commit('addFloorList', res.data)
    }
  },
  getters: {

  }
}
